package com.bbm.communitysystem.domain.dto.role;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

/**
 * <p>
 * 
 * </p>
 *
 * @author bbm
 * @since 2025-02-13
 */
@Data
@Schema(description = "规则实体类")
public class RoleDto {

    @Schema(description = "角色唯一标识")
    private Integer id;

    /**
     * 角色名称
     */
    @Schema(description = "角色名称", example = "系统管理员")
    private String Name;

    /**
     * 路由id
     */
    @Schema(description = "路由ID集合（逗号分隔）", example = "1,3,5")
    private String router;

    /**
     * 角色权限id
     */
    @Schema(description = "权限ID集合（逗号分隔）", example = "2,4,6")
    private String Per;

    /**
     * 权限id
     */
    @Schema(description = "权限对象集合")
    private PerDto[] perId;

    /**
     * 路由id
     */
    @Schema(description = "路由对象集合")
    private RouterDto[] routerId;

    /**
     * 角色描述
     */
    @Schema(description = "角色描述", example = "拥有系统所有权限，可以进行系统配置管理")
    private String roleDescription;

    /**
     * 上传者
     */
    @Schema(description = "最后操作人", example = "admin")
    private String updateBy;

    /**
     * 启用 0不启用
     */
    @Schema(description = "状态（1-启用，0-禁用）", allowableValues = {"0", "1"})
    private String status;

    // ... 原有getPerIndex和getRouterIndex方法保持不变 ...

    public Integer[] getPerIndex() {
        if (this.Per == null) {
            return null;
        }
        String[] i = this.Per.split(",");
        Integer[] perIndex = new Integer[i.length];
        for (int j = 0; j < i.length; j++) {
            perIndex[j] = Integer.parseInt(i[j]);
        }
        return perIndex;
    }

    public Integer[] getRouterIndex() {
        if (this.router == null) {
            return null;
        }
        String[] i = this.router.split(",");
        Integer[] routerIndex = new Integer[i.length];
        for (int j = 0; j < i.length; j++) {
            routerIndex[j] = Integer.parseInt(i[j]);
        }
        return routerIndex;
    }

}
